import { Post, Get, Put, Delete } from '@/utils/api.js'

const url = '/api/note'

// Trading Account
export function ListTradingAccount() {
  return Get(url + '/trading_accounts')
}

export function CreateTradingAccount(name, remark) {
  return Post(url + '/trading_accounts', { name, remark })
}

export function UpdateTradingAccount(id, name, remark) {
  return Put(url + '/trading_accounts/' + id, { name, remark })
}

export function DeleteTradingAccount(id) {
  return Delete(url + '/trading_accounts/' + id)
}

export function SetDefaultTradingAccount(id) {
  return Put(url + '/trading_accounts/' + id + '/set-default')
}

// Stock
export function ListStock(tradingAccountId, key, page, pageSize) {
  let b_url = url + '/trading_accounts/' + tradingAccountId
  return Get(b_url + '/stocks', { key, page, pageSize })
}

export function GetStock(tradingAccountId, id) {
  let b_url = url + '/trading_accounts/' + tradingAccountId
  return Get(b_url + '/stocks/' + id)
}

export function CreateStock(tradingAccountId, code) {
  let b_url = url + '/trading_accounts/' + tradingAccountId
  return Post(b_url + '/stocks', { code })
}

export function UpdateStock(tradingAccountId, id, name) {
  let b_url = url + '/trading_accounts/' + tradingAccountId
  return Put(b_url + '/stocks/' + id, { name })
}

export function DeleteStock(tradingAccountId, id) {
  let b_url = url + '/trading_accounts/' + tradingAccountId
  return Delete(b_url + '/stocks/' + id)
}

// Plan
export function ListPlan(tradingAccountId, stockId, key, page, pageSize) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Get(b_url + '/plans', { key, page, pageSize })
}

export function GetPlan(tradingAccountId, stockId, id) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Get(b_url + '/plans/' + id)
}

export function CreatePlan(
  tradingAccountId,
  stockId,
  title,
  takeProfitPrice,
  stopLossPrice,
  valuationAnalysis,
) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Post(b_url + '/plans', {
    stockId,
    title,
    takeProfitPrice,
    stopLossPrice,
    valuationAnalysis,
  })
}

export function UpdatePlan(
  tradingAccountId,
  stockId,
  id,
  title,
  takeProfitPrice,
  stopLossPrice,
  valuationAnalysis,
) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Put(b_url + '/plans' + id, { title, takeProfitPrice, stopLossPrice, valuationAnalysis })
}

export function DeletePlan(tradingAccountId, stockId, id) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Delete(b_url + '/plans/' + id)
}

export function SetPlanStatus(tradingAccountId, stockId, id, status) {
  let b_url = url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId
  return Put(b_url + '/plans' + id + '/set-status', { status })
}

// Transaction Record
export function ListTransRecord(tradingAccountId, stockId, planId) {
  let b_url =
    url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId + '/plans/' + planId
  return Get(b_url + '/trans_records')
}

export function GetTransRecord(tradingAccountId, stockId, planId, id) {
  let b_url =
    url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId + '/plans/' + planId
  return Get(b_url + '/trans_records/' + id)
}

export function CreateTransRecord(
  tradingAccountId,
  stockId,
  planId,
  date,
  action,
  price,
  quantity,
  reason,
) {
  let b_url =
    url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId + '/plans/' + planId
  return Post(b_url + '/trans_records', { stockId, date, action, price, quantity, reason })
}

export function UpdateTransRecord(
  tradingAccountId,
  stockId,
  planId,
  id,
  action,
  price,
  quantity,
  reason,
) {
  let b_url =
    url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId + '/plans/' + planId
  return Put(b_url + '/trans_records/' + id, { action, price, quantity, reason })
}

export function DeleteTransRecord(tradingAccountId, stockId, planId, id) {
  let b_url =
    url + '/trading_accounts/' + tradingAccountId + '/stocks/' + stockId + '/plans/' + planId
  return Delete(b_url + '/trans_records/' + id)
}
